<!DOCTYPE html>
<html lang="zh-CN">

<head>
  <meta charset="utf-8">
  <title>Sign in &laquo; Admin</title>
  <link rel="stylesheet" href="../assets/vendors/bootstrap/css/bootstrap.css">
  <link rel="stylesheet" href="../assets/css/admin.css">
</head>

<body>
  <div class="login">
    <div class="login-wrap">
      <img class="avatar" src="../assets/img/default.png">
      <!-- 有错误信息时展示 -->
      <!-- <div class="alert alert-danger">
        <strong>错误！</strong> 用户名或密码错误！
      </div> -->
      <div class="form-group">
        <label for="email" class="sr-only">邮箱</label>
        <input id="email" type="email" class="form-control" placeholder="邮箱" autofocus>
      </div>
      <div class="form-group">
        <label for="password" class="sr-only">密码</label>
        <input id="password" type="password" class="form-control" placeholder="密码">
      </div>
      <button class="btn btn-primary btn-block" id="loginBtn"> 登 录</button> 
      </div> 
    </div> 
    <script src="../assets/vendors/jquery/jquery.min.js"></script>
        <script>
          $(function () {
            //获取登录按钮并为其添加点击事件
            $('#loginBtn').on('click', function () {
              //获取用户输入的邮箱和密码信息
              var email = $('#email').val();
              var password = $('#password').val();
              //判断用户输入的邮箱和密码信息是否为空，如果为空阻止代码向下执行，并弹出提示信息
              if (email.trim().length === 0) {
                alert('邮箱不能为空');
                return;
              }
              if (password.trim().length === 0) {
                alert('密码不能为空');
                return;
              }
              //发送ajax请求
              $.ajax({
                type: 'post',
                url: 'http://47.111.184.55:3000/login',
                data: {
                  email: email,
                  password: password,
                },
                success: function (response) {
                  location.href = 'index.html';
                },
                error: function (response) {
                  alert('用户名或者密码不正确');
                }
              });
            });
          });
        </script>
</body>

</html>